const app = getApp()
import {
  HomeIndex
} from 'index-modal.js';
import {
  Config
} from '../../../utils/config.js';
var Function = require("../../../utils/function.js");
var index = new HomeIndex(); //实例化 首页 对象

Page({
  data: {
    longitude:0,
    latitude: 0,
    markers:[],
    maparr:[],  //所有门店的位子
    accuracy:0,
    count:0,
    zero:19999,
    id:'',
    isclick:false,
    deles:{},
    animationData:'' //动画
  },
  //事件处理函数
  bindViewTap: function() {
   
  },
  onLoad: function (options) {
    var that=this
    this.setData({ longitude: options.weidu, latitude:options.jingdu})
    this._maplist()
    
  },
  createMarker(marke) {
  
    let markers = [];
    for (let j = 0; j < marke.length;j++){
      let marker = {
        id:j,
        iconPath: "/images/selt-id.png",
        latitude: marke[j].weidu,
        longitude: marke[j].jingdu,
        width: 52,
        height: 60,
        status:false
      };
      markers.push(marker)
    }
    this.setData({ markers})
    
   },
  markertap(e) {
    // if (this.data.isclick) {
    //   this.setData({ isclick: false })
    // }
    var that =this;

    var animation = wx.createAnimation({
      duration: 300,
      timingFunction: "linear",
      delay: 0
    })
    that.animation = animation
    animation.translate(0, 300).step()
    that.setData({
      animationData: animation.export()
    })
     let j = parseInt(e.markerId);
     let markers = this.data.markers;
      //markers[j].iconPath = "/images/setbank.png"
     markers.forEach((item,index)=>{
         if(index == j){
           if (item.status){
              return;
            }else{
             item.status = true
             item.iconPath = "/images/setbank.png"
           }  
         }else{
           item.status =false;
           item.iconPath = "/images/selt-id.png"
         }
     })
     this.setData({
       markers,
       id: this.data.maparr[j].id, 
     })

    this.mapshow()

  },
  _maplist(){
     let that =this;
     let data ={
       jingdu: that.data.longitude,
       weidu: that.data.latitude
     };
     index.maplist(data,(res)=>{
       if(res.code == 200){
         that.setData({
           maparr:res.data,
           count:res.count
         })
         that.createMarker(that.data.maparr)
       }
     })
  },
  mapshow:function(){
    let that = this;
    let data = {
      id:that.data.id,
      jingdu: that.data.longitude,
      weidu: that.data.latitude
    };
    index.maplist(data, (res) => {
      if (res.code == 200) {
        that.setData({
          deles:res.data,
          // isclick:true
        })

        var animation = wx.createAnimation({
          duration: 800,
          timingFunction: "linear",
          delay: 0
        })
        that.animation = animation
        animation.translate(0,0).step()
        that.setData({
          animationData: animation.export()
        })
      }
    })
  },
  gogun(e){
    let id = e.currentTarget.dataset.id;
    wx.redirectTo({
      url: '../detail/detail?id='+id
    })
  }


})